﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.Split;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0212", Name = "第N行特定部分有/无记载", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0212 : VerfityOneResult
    {
        [Category("设定检查的行"), Description("要检查的行")]
        public int Row { get; set; }

        [Category("有/无记录"), Description("true:有记录 false:无记录")]
        public bool Exists { get; set; }

        [Category("要检查的部分"), Description("指定要检查的部分")]
        public EnumSpeicficEntryPart SpeicficPart 
        {
            get { return this._speicficPart; }
            set { this._speicficPart = value; }
        }
        
        public EnumSpeicficEntryPart _speicficPart = EnumSpeicficEntryPart.All;
        
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (result == null  )
            {
                return false;
            }
            
            bresult = CheckSpecificRowIsEmpty(result, GetSpeicficResult,Exists, Row);

            //一下内容转移到基类
           /* if (Exists)
            {
                //判断有记录

                if (Row - 1 < result.Count && Row - 1 > 0)
                {
                    //判断第N行是否有记载内容，将左斜线替换成空字符。
                    bresult = result[Row - 1].Any(colStr => !string.IsNullOrEmpty(colStr.Replace("/", string.Empty)));
                }
            }
            else
            {
                if (Row - 1 >= result.Count)
                {
                    bresult = true;
                }
                else if (Row - 1 < result.Count && Row - 1 > 0)
                {
                    //判断第N行是否有空白，将左斜线替换成空字符。
                    bresult = result[Row - 1].Any(colStr => string.IsNullOrEmpty(colStr.Replace("/", string.Empty)));
                }
            }*/

            if (bresult)
            {
                System.Console.WriteLine("VerfityRq0212");
            }

            return bresult;
        }
        
        private string GetSpeicficResult(string colResult)
        {
            switch (this.SpeicficPart)
            { 
                case EnumSpeicficEntryPart.All:
                    return colResult.Replace("/", string.Empty);
                case EnumSpeicficEntryPart.DateTime:
                    return new SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult).GetDate().Replace("/", string.Empty);
                case EnumSpeicficEntryPart.Text:
                    return new SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult).GetText();
                default :
                    return "";
            }
        }
    }
}
